package com.pd.backend.service.impl;

import com.pd.backend.entity.PdOrderClassifyOrder;
import com.pd.backend.dao.PdOrderClassifyOrderDao;
import com.pd.backend.service.PdOrderClassifyOrderService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 订单分类订单关联表(PdOrderClassifyOrder)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:34
 */
@Service("pdOrderClassifyOrderService")
public class PdOrderClassifyOrderServiceImpl implements PdOrderClassifyOrderService {
    @Resource
    private PdOrderClassifyOrderDao pdOrderClassifyOrderDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdOrderClassifyOrder queryById(String id) {
        return this.pdOrderClassifyOrderDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdOrderClassifyOrder 筛选条件
     * @param pageRequest          分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdOrderClassifyOrder> queryByPage(PdOrderClassifyOrder pdOrderClassifyOrder, PageRequest pageRequest) {
        long total = this.pdOrderClassifyOrderDao.count(pdOrderClassifyOrder);
        return new PageImpl<>(this.pdOrderClassifyOrderDao.queryAllByLimit(pdOrderClassifyOrder, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdOrderClassifyOrder 实例对象
     * @return 实例对象
     */
    @Override
    public PdOrderClassifyOrder insert(PdOrderClassifyOrder pdOrderClassifyOrder) {
        this.pdOrderClassifyOrderDao.insert(pdOrderClassifyOrder);
        return pdOrderClassifyOrder;
    }

    /**
     * 修改数据
     *
     * @param pdOrderClassifyOrder 实例对象
     * @return 实例对象
     */
    @Override
    public PdOrderClassifyOrder update(PdOrderClassifyOrder pdOrderClassifyOrder) {
        this.pdOrderClassifyOrderDao.update(pdOrderClassifyOrder);
        return this.queryById(pdOrderClassifyOrder.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdOrderClassifyOrderDao.deleteById(id) > 0;
    }
}
